<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/6
  Time: 10:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>图书首页</title>
  </head>
  <body>
     <c:if test="${sessionScope.user==null}">
         <c:redirect url="/login.jsp"/>
     </c:if>
      <h1>欢迎${sessionScope.user.realname}访问图书管理系统</h1>
     <button onclick="location.href='/bookadd.jsp'">添加</button>
      <table width="80%" border="1" cellpadding="0" cellspacing="0" align="center">
           <tr>
             <th>编号</th>
             <th>书名</th>
             <th>价格</th>
             <th>出版社</th>
             <th>操作</th>
           </tr>
           <c:forEach items="${requestScope.books}" var="b">
               <tr>
                 <td>${b.id}</td>
                 <td>${b.name}</td>
                 <td>${b.price}</td>
                 <td>${b.publisher}</td>
                 <td>
                     <%--onclick:点击事件。del()触发该方法--%>
                     <a onclick="del(${b.id})">删除</a>
                     <a href="/book?method=getById&id=${b.id}">修改</a>
                 </td>
               </tr>
           </c:forEach>
      </table>
  </body>
  <%--script表示js的代码.--%>
<script>
     //function 定义方法。
     function del(id){
         var b = confirm("是否删除该记录?");
         if(b){
             location.href="/book?method=delete&id="+id;
         }
     }
</script>
</html>
